﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ImageUploaderComponent.Data;

namespace ImageUploaderComponent {
    public partial class AgDataGridView : IDataGridView {
        public AgDataGridView() {
            InitializeComponent();
            Loaded += AgDataGridView_Loaded;
            agDataGrid.FocusedRowChanged += agDataGrid_FocusedRowChanged;
        }

        void agDataGrid_FocusedRowChanged(object sender, DevExpress.Data.FocusedRowChangedEventArgs e)
        {
            if (SelectionChanged != null)
            {
                SelectionChanged(sender, SelectedItem);
            }
        }




        void AgDataGridView_Loaded(object sender, RoutedEventArgs e)
        {
//            agDataGrid.DataSource = ((UploaderViewModel) DataContext).ImageDataList;
        }

        public event DataGridView.GridSelectionChangedHandler SelectionChanged;

        public ImageData SelectedItem{
            get { 
                int rowHandle =  agDataGrid.GetSelectedRows()[0];
                return (ImageData)agDataGrid.GetDataRow(rowHandle);
            }
        }

        public UploaderViewModel ItemsSource{
            get { throw new NotImplementedException(); }
            set{
                agDataGrid.DataSource = value.ImageDataList;
            }
        }

        public static readonly DependencyProperty DataContextWatcherProperty =
    DependencyProperty.Register("DataContextWatcher",
                        typeof(Object), typeof(AgDataGridView),
                        new PropertyMetadata(dataContextChanged));

        private static void dataContextChanged(object sender,
                                               DependencyPropertyChangedEventArgs e)
        {
            var control = (AgDataGridView)sender;
//            control.ItemsSource = e.NewValue as UploaderViewModel;
        }
    }
}
